package wec_wallet.ebo.com.util;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

import bassproject.ebo.com.ebobass.utils.IToast;
import wec_wallet.ebo.com.R;

/**
 * Created by Administrator on 2018/3/9.
 */

public class PermissionsChecker {

    // 判断权限集合
    public static boolean lacksPermissions(Activity mContext,String... permissions) {
        for (String permission : permissions) {
            if (lacksPermission(mContext,permission)) {
                return true;
            }
        }
        return false;
    }

    // 判断是否缺少权限
    public static boolean lacksPermission(Activity mContext,String permission) {
        return ContextCompat.checkSelfPermission(mContext, permission) ==
                PackageManager.PERMISSION_DENIED;
    }
    // 显示缺失权限提示
    public static  void showMissingPermissionDialog(final Activity context, final int requestCode, String title, final String msg , final String... permissions) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(R.string.help);
        builder.setMessage(msg);

        // 拒绝, 退出应用
        builder.setNegativeButton(R.string.quit, new DialogInterface.OnClickListener() {
            @Override public void onClick(DialogInterface dialog, int which) {
//                setResult(PERMISSIONS_DENIED);
//                finish();
                IToast.show(msg);
            }
        });

        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
            @Override public void onClick(DialogInterface dialog, int which) {
                requestPermissions(context,requestCode,permissions);
            }
        });

        builder.show();
    }
    /*      * 申请授予权限
      * CALL_PHONE  READ_EXTERNAL_STORAGE CAMERA  READ_CONTACTS GET_ACCOUNTS ACCESS_FINE_LOCATION
      */
    public  static  void requestPermissions(Activity context, int requestCode,String... permissions)
    {
        ActivityCompat.requestPermissions(context,
                permissions,
                requestCode);

    }


}
